package com.health.controller;

import com.health.common.PageBean;
import com.health.common.PageQueryDTO;
import com.health.common.Result;
import com.health.exception.CustomerException;
import com.health.pojo.Checkitem;
import com.health.service.CheckitemService;
import com.mysql.cj.protocol.x.MessageConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.juli.logging.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangzhen
 * @version 1.0
 * @date 2025/1/16 21:38
 */
@Slf4j
@RestController
@RequestMapping("/checkitem")
public class CheckitemController {
    @Autowired
    private CheckitemService checkitemService;
    @PostMapping ("/findPage")
    public PageBean findPage(@RequestBody PageQueryDTO pageQueryDTO){
        PageBean<Checkitem> page = checkitemService.findPage(pageQueryDTO);
        log.info("pageQueryDTO:{}",pageQueryDTO);
        return  page;
    }
    @PostMapping("/add")
    public Result add(@RequestBody Checkitem checkitem){
            log.info("checkitemL{}",checkitem);
        try {
            checkitemService.add(checkitem);
        } catch (Exception e) {
            return Result.error("添加失败，请联系管理员");
        }
        return Result.success("添加成功!!");
    }
    @GetMapping ("/delete")
    public Result deleteById(@RequestParam Integer id){
            log.info("id:{}",id);
        try {
            checkitemService.deleteById(id);
        } catch (Exception e) {
            return Result.error("删除失败，请联系管理员");
        }
        return Result.success("删除成功");
    }
    @GetMapping("/findById")
    public Result findById(@RequestParam Integer id) {
        log.info("id:{}", id);
         Checkitem checkitem = checkitemService.findById(id);
          return Result.success(checkitem);
    }
    @PostMapping("/edit")
    public Result update(@RequestBody Checkitem checkitem)
    {
        log.info("checkitem:{}",checkitem);
         checkitemService.update(checkitem);
        return Result.success("成功");
    }
    @GetMapping("/findAll")
    public Result findall()
    {
        List<Checkitem> checkitems=checkitemService.findAll();
        return Result.success(checkitems);
    }

}